#!/usr/bin/env python

import sys
import json

counter = {}

def reducer():
    for line in sys.stdin:
        if len(line.split('\t'))!=3:
            continue
        seg = line.strip().split('\t')
        key = seg[0]
        vcount = int(seg[1])
        vcontent = json.loads(seg[2])
        
        c = counter.get(key,[0,''])
        c[0]+=vcount
        if c[1]=='':
            pcontent={"": [[[], [], [], [], [], []], [], {}, [{}, {}], [0, 0], [0, 0], 0]}
                         #s_id date positions      btime step action   c_tag   s_tag   6
        else:
            pcontent=json.loads(c[1])
        for i in range(6):
            pcontent[''][0][i].append(vcontent[''][0][i])
        for i in range(1,2):
            pcontent[''][i].append(vcontent[''][i])
        for i in range(2,3):
            for ks in vcontent[''][i]:
                st=pcontent[''][i].get(ks,0)
                st+=vcontent[''][i][ks]
                pcontent[''][i][ks]=st
        for i in range(2):
            for kk in vcontent[''][3][i]:
                b=pcontent[''][3][i].get(kk,0)
                b+=vcontent[''][3][i][kk]
                pcontent[''][3][i][kk]=b
        for i in range(4,6):
            for tag in range(2):
                pcontent[''][i][tag]+=vcontent[''][i][tag]
        pcontent[''][6]+=vcontent[''][6]
        
        c[1]=json.dumps(pcontent)
        counter[key]=c

    for k,v in counter.iteritems():
        #print "%s\t%s" %(k,v)
        print "%s\t%s\t%s" %(k,v[0],v[1])

if __name__ == '__main__':
    reducer()
